#include "test_call_control.h"
#include "cm_uart.h"
#include "cm_demo_uart.h"
#include "cm_audio_common.h"
#include "cm_audio_player.h"


static void __playerfile_process_event(cm_audio_play_event_e event)
{
    if (event == CM_AUDIO_PLAY_EVENT_FINISHED)
    {      
        cm_audio_player_stop();
    }
}

static void  test_call_start_cb(void)
{
    cm_demo_printf("cm_audio_play_file ret:%d\n",cm_audio_play_file("/Audio/test.mp3", CM_AUDIO_PLAY_FORMAT_MP3, NULL, __playerfile_process_event, "FILEMP3"));
    osDelay(100);
}

static void  test_call_stop_cb(void)
{
    cm_demo_printf("cm_audio_play_file ret:%d\n",cm_audio_play_file("/Audio/test.mp3", CM_AUDIO_PLAY_FORMAT_MP3, NULL, __playerfile_process_event, "FILEMP3"));
    osDelay(100);
}

void cm_test_call_control_operation(unsigned char *cmd[],int len)
{
    if(0 == strncmp("SET_MODE",cmd[2],strlen("SET_MODE")))
    {
        if(0 == strncmp("AT_MODE",cmd[3],strlen("AT_MODE")))
        {
            cm_call_control_set_voice_call_mode(CM_CC_VOICE_CALL_AT_MODE);
            cm_call_control_set_user_start_event(NULL);
            cm_call_control_set_user_stop_event(NULL);
            cm_demo_printf("cm_call_control_set_voice_call_mode no return\n");
        }else if(0 == strncmp("USER_MODE",cmd[3],strlen("USER_MODE")))
        {
            cm_call_control_set_voice_call_mode(CM_CC_VOICE_CALL_USER_MODE);
            cm_demo_printf("cm_call_control_set_voice_call_mode no return\n");
        }else
        {
            cm_demo_printf("param error!\n");
        }

    }else if(0 == strncmp("SET_START_EVENT",cmd[2],strlen("SET_START_EVENT")))
    {
        cm_call_control_set_user_start_event(test_call_start_cb);
        cm_demo_printf("cm_call_control_set_user_start_event no return\n");
    }
    else if(0 == strncmp("SET_STOP_EVENT",cmd[2],strlen("SET_STOP_EVENT")))
    {
        cm_call_control_set_user_stop_event(test_call_stop_cb);
        cm_demo_printf("cm_call_control_set_user_stop_event no return\n");
    }
    else
    {
        cm_demo_printf("param error!\n");
    }
}